// 任务下发模块

import { observer } from "mobx-react";
import "./index.less"
import { Card, Spin, Button, Row, Col, Form, Input, Divider, Descriptions, Table } from 'antd';
import { PlayCircleOutlined } from '@ant-design/icons';
import store from "./model.ts"
import Menu from "../publicComponent/menu/index.jsx"
import { history } from "umi";
import Scan from "../publicComponent/scan"
import { useEffect, useState } from "react";
import indexStore from "../model"
import FingerApi from "../finger_device/model"


function Index() {

    let [form] = Form.useForm()

    // 30s更新一次当日指纹
    let timer = null
    useEffect(() => {
        indexStore.dayFingerprint()
        timer = setInterval(() => {
            indexStore.dayFingerprint()
        }, 30000)
        // 销毁定时器
        return function () {
            if (timer) {
                clearInterval(timer)
            }
        }
    }, [])


    // 进入页面就开始扫描
    useEffect(() => {
        // 默认扫描不停止
        store.isStop = false
        store.contrast()
    }, [])

    // 记录最后一次跳转路由path
    // 设置窗口大小和位置
    let t = null
    useEffect(() => {
        indexStore.StoragePath(history.location.pathname)
        t = setTimeout(() => {
            FingerApi.minimizeWindow()
        }, 3000);
        return function(){
            if(t){
                clearTimeout(t)
            }
        }
    }, [])

    // 处方表头
    let columns = [
        {
            title: '序号',
            dataIndex: 'index',
            align: "center",
            width: 55
        },
        {
            title: '处方名',
            dataIndex: 'planName',
            align: "center"
        },
        {
            title: '诊疗技术',
            dataIndex: 'technology',
            align: "center"
        },
        {
            title: '诊疗次数',
            dataIndex: 'numberOfTimes',
            align: "center"
        },
        {
            title: '开发时间',
            dataIndex: 'createTime',
            align: "center"
        },
        {
            title: '医师',
            dataIndex: 'createUser',
            align: "center"
        },
        // {
        //     title: '是否已完成',
        //     align: "center",
        //     render: function() {
        //         return(
        //             <span>
        //                 <a>已完成</a>
        //             </span>
        //         )
        //     }
        // },
    ]

    let clickNum = 0
    let time = null
    // 连点3次才能退出
    function goback() {
        if (clickNum == 0) {
            clickNum += 1
            time = new Date().getTime()
        } else {
            if ((new Date().getTime() - time) < 800) {
                clickNum += 1
                time = new Date().getTime()
            } else {
                clickNum = 0
            }
        }
        if (clickNum === 3) {
            history.push({ pathname: "/", query: { name: "child" } })
            indexStore.StoragePath("/")
            store.isStop = true
        }
    }

    return (
        <>
            <Spin tip="加载中" spinning={store.loading} size="large">
                <div className="allocation">
                    <div className="allocation-title">
                        {/* <img onClick={goback} src={require("../../assets/images/向左箭头.png")} alt="" /> */}
                        <span onClick={goback}>TMS方式</span>
                    </div>
                    <div className="allocation-body">
                        请长按手指
                    </div>
                </div>
            </Spin>
        </>
    )
}

export default observer(Index)